package com.itheima.dao;

import com.itheima.domain.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;


/**
 * 预约订单数据的持久层
 */
public interface OrderDao {

    /**
     * 根据预约日期查询预约订单数据
     * @param orderDate
     */
    @Select("select * from t_order where member_id=#{memberId} and orderDate=#{orderDate} and setmeal_id=#{setmealId}")
    Order selectOrderByOrderDate(@Param("memberId") Integer memberId,@Param("orderDate") String orderDate,@Param("setmealId") Integer setmealId);


    /**
     * 添加预约订单
     * @param order
     */
    void insertOrder(Order order);


    /**
     * 根据预约订单id查询成功预约后的订单信息
     * @param id
     * @return
     */
    Map<String,Object> findAssociateOrderById(Integer id);

    /**
     * 查询当天预约人数
     * @param date
     * @return
     */
    @Select("select count(id) from t_order where orderDate =#{date}")
    Integer findOrderCountByDate(String date);

    /**
     * 查看本周或本月预约人数
     * @param date
     * @return
     */
    @Select("select count(id) from t_order where orderDate >=#{date}")
    Integer findOrderCountAfterDate(String date);

    /**
     * 查看当天到诊人数
     * @param date
     * @return
     */
    @Select("select count(id) from t_order where orderDate =#{date} and orderStatus='已到诊'")
    Integer findVisitsCountByDate(String date);

    /**
     * 查看本周或者本月到诊人数
     * @param date
     * @return
     */
    @Select("select count(id) from t_order where orderDate >=#{date} and orderStatus='已到诊'")
    Integer findVisitsCountAfterDate(String date);

    /**
     * 查询热门套餐
     * @return
     */
    @Select("select s.name,count(o.id) setmeal_count,count(o.id)/(select count(id) from t_order) proportion from t_order o,t_setmeal s where s.id=o.setmeal_id group by s.name order by count(o.id) desc limit 0,2")
    List<Map> findHotSetmeal();
}
